package com.jiegui.common.model;

import com.jiegui.common.utils.JsonUtils;
import lombok.Data;

import java.util.HashMap;

@Data
public class MessageSendModel {
    /**
     * 接收者openid
     */
    private String touser;
    /**
     * JWID
     */
    private String jwid;
    /**
     * 模板ID
     */
    private String templateId;

    /**
     * 模板跳转链接（海外帐号没有跳转能力）
     */
    private String url;

    /**
     * 跳小程序所需数据，不需跳小程序可不用传该数据
     */
    private String miniProgram;

    /**
     * 所需跳转到的小程序appid
     */
    private String appId;

    /**
     * 所需跳转到小程序的具体页面路径，支持带参数,（示例index?foo=bar）
     */
    private String pagePath;

    private String data;

    private String  type;


    private MessageSendModel.TemplateItem items = new MessageSendModel.TemplateItem();





    @Override
    public String toString() {
        return "TmessageSendVO{" +
                "touser='" + touser + '\'' +
                ", templateId='" + templateId + '\'' +
                ", url='" + url + '\'' +
                ", miniProgram='" + miniProgram + '\'' +
                ", appId='" + appId + '\'' +
                ", pagePath='" + pagePath + '\'' +
                ", data='" + data + '\'' +
                ", jwid='" + jwid + '\'' +
                '}';
    }

    public static MessageSendModel New() {
        return new MessageSendModel();
    }

    public MessageSendModel add(String key, String value) {
        this.items.put(key, new MessageSendModel.Item(value));
        return this;
    }

    public String build() {
        return JsonUtils.toJson(this);
    }

    public String buildData() {
        String str = JsonUtils.toJson(this.items);
        this.data = str;
        return str;
    }


    public class Item {
        private Object value;
//        private String color;

        public Object getValue() {
            return this.value;
        }

        public void setValue(Object value) {
            this.value = value;
        }


        public Item(Object value) {
            this.value = value;
        }
    }

    public class TemplateItem extends HashMap<String, Item> {
        private static final long serialVersionUID = -3728490424738325020L;

        public TemplateItem() {
        }

        public TemplateItem(String key, MessageSendModel.Item item) {
            this.put(key, item);
        }
    }
}
